package com.share.common.enums;

import lombok.Getter;

import java.util.Optional;

@Getter
public enum RedisChannelEnum {
    USER("user", "redis用户通道"),
    DEVELOP("develop", "测试环境");

    public String code;
    public String name;

    private RedisChannelEnum(final String code, final String name) {
        this.code = code;
        this.name = name;
    }

    public static RedisChannelEnum toEnum(final String code) {
        for (final RedisChannelEnum tag : RedisChannelEnum.values()) {
            if (tag.code.equals(code)) {
                return tag;
            }
        }
        return null;
    }

    public static String toName(final String code) {
        return Optional.ofNullable(toEnum(code)).map(item -> item.name).orElse(null);
    }
}
